package com.zjitc;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zjitc.common.ServerResponse;
import org.junit.Test;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/27 15:34
 * @description:
 */
public class JsonDataSource {

  private static final Gson gson = new GsonBuilder().create();

  @Test
  public void gsonTest(){
    ServerResponse response = null;

    response = ServerResponse.createSuccess();
    printAsJson(response);

    response = ServerResponse.createError();
    printAsJson(response);

    response = ServerResponse.createSuccess("注册成功");
    printAsJson(response);

    response = ServerResponse.createError("注册失败");
    printAsJson(response);
  }

  private void printAsJson(ServerResponse response) {
    System.out.println(gson.toJson(response));
  }
}
